<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<link rel="stylesheet" href="css/bootstrap.css" />
		<link rel="stylesheet" href="css/ClearTheDefaultStyle.css" />
		<link rel="stylesheet" href="css/paper_queries.css" />
		<script src="js/jquery.js"></script>
		<script src="js/imagesloaded.pkgd.min.js"></script>
		<script src="js/masonry.pkgd.js"></script>
		<script src="node_modules/axios/dist/axios.js"></script>
		<script src="js/register.js"></script>
	</head>
	<body>
		<div class="load">
			<div class="load_yuan"></div>
		</div>
		<div class="masonry"></div>
	</body>
	<script>
		let admin = new Admin();
		//判断是否有权限
		admin.jurisdiction();
		let nickname = "";
		function getUser(id) {
			return axios({
				method: "get",
				url: "https://ty.php800.cn/api/article/getuser.php",
				headers: {
					SAT: "1234567",
				},
				params: {
					userid: parseInt(id),
				},
			}).then((res) => {
				console.log(res.data.member[0] === undefined);
				//没有找到用户时返回未知
				return res.data.member[0] === undefined ? "未知" : res.data.member[0].nickname;
			});
		}
		async function fillUser(data) {
			let template = document.createElement("template");
			let num = 0;
			for (let i = data.length - 1; i > 0; i--) {
				num++;
				let { body, classid, datetime, id, title, userid } = data[i];
				let nickname = await getUser(userid);
				item = document.createElement("div");
				item.className = "item col-sm-4";
				item.style = `--i:${num}`;
				item.innerHTML = `<div>
									<a href="article_details.html?id=${id}" id="title">${title}</a>
									<div class='qwq'>
										<span id='name'>${nickname}</span><span id="time">${admin.getdate(parseInt(datetime))}</span>
									</div>
								</div>`;
				template.appendChild(item);
			}
			return template;
		}
		axios
			.get("https://ty.php800.cn/api/article/list.php", {
				headers: {
					SAT: "1234567",
				},
			})
			.then((result) => {
				Await(result.data.blogs).then((item) => {
					$(function () {
						var $container = $(".masonry");
						$container.imagesLoaded(function () {
							$container.masonry({
								itemSelector: ".item",
							});
						});
					});
				});
			});

		async function Await(res) {
			let template = await fillUser(res);
			document.querySelector(".load").style.display = "none";
			template.style.display = "block";
			document.querySelector(".masonry").appendChild(template);
		}
	</script>
</html>
